home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / Snippets / Devices / Wake100 / WakeINIT.c < prev   
Encoding:
C/C++ Source or Header  |  1992-09-01  |  1.3 KB  |  57 lines  |  [TEXT/MPS ]

  1. //
  2. //
  3. // © Copyright 1991 Apple Computer, Inc.  All Rights Reserved
  4. //
  5. // By Ricardo Batista
  6. //
  7. // This is an INIT which reads the wake up time in the PowerBook 100 and
  8. // old Portable, if the wake up date has elapsed then we add a day to it
  9. // so that the machine wakes up at the same time every day.
  10. // By request of Neal Macklin.  Maybe we can make something useful from
  11. // this later on.
  12. //
  13. //  This file is an INIT that loads a code resource and installs it in
  14. // the sleep queue.
  15.  
  16. #define        SystemSevenOrLater    1
  17.  
  18. #include <Types.h>
  19. #include <Power.h>
  20. #include <Resources.h>
  21. #include <Memory.h>
  22. #include <GestaltEqu.h>
  23.  
  24. typedef unsigned long         ulong;
  25.  
  26.  
  27. main()
  28. {
  29.     SleepQRec *slQ;
  30.     Handle H;
  31.     ProcPtr p;
  32.     short err;
  33.     long g = 0L;
  34.     
  35.     err = Gestalt(gestaltPowerMgrAttr,&g);
  36.     if (err)
  37.         return;
  38.     if ((g && (1 << gestaltPMgrExists)) == 0)        // is there power Mgr ?
  39.         return;
  40.     H = GetResource('Wake',0);
  41.     if (!H)
  42.         return;
  43.     LoadResource(H);
  44.     HLock(H);
  45.     DetachResource(H);
  46.     p = (ProcPtr) StripAddress(*H);
  47.     (*p)();                                // execute our proc, since we just restarted
  48.     slQ = (SleepQRec*) NewPtrSys(sizeof(SleepQRec));
  49.     if (!slQ)
  50.         return;
  51.     slQ = (SleepQRec*) StripAddress(slQ);
  52.     slQ->sleepQLink = 0L;
  53.     slQ->sleepQType = sleepQType;
  54.     slQ->sleepQProc = p;
  55.     slQ->sleepQFlags = 0;
  56.     SleepQInstall(slQ);                    // install our sleep proc
  57. }